package com.lz.config.common.security.domain;

import java.util.*;
import com.lz.config.dal.entity.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;

public class MyUserDetails implements UserDetails, Serializable {
    private User user;

    public MyUserDetails() {
    }

    public MyUserDetails(User user) {
        this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    //账号是否未过期 默认永不过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    //账号是否未锁定 默认未锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    //密码是否未过期   默认永不过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    //账号是否可用
    @Override
    public boolean isEnabled() {
        return true;
    }

    /**
     * 获取
     * @return user
     */
    public User getUser() {
        return user;
    }

    /**
     * 设置
     * @param user
     */
    public void setUser(User user) {
        this.user = user;
    }

    public String toString() {
        return "MyUserDetails{user = " + user + "}";
    }
}
